package com.pq.dao.product;

import com.pq.pojo.order.OrderCart;
import com.pq.pojo.order.OrderTable;
import com.pq.pojo.product.Product;
import com.pq.pojo.product.ProductImg;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Mapper
public interface ProductDao {
    // typeId 商品所属分类ID, orderCol按 销量(sales)还是价格(price)排序
    List<Product> findProductListByTypeId(Integer typeId, Integer startIndex, Integer rows, String orderCol);

    // byFlag 有两个参数 最新(new)和最热(hot), orderCol是否按price排序
    List<Product> findProductList(String byFlag, String orderCol, Integer startIndex, Integer rows);

    Product findProductById(Integer productId);

    Product findProductDetailByProductId(Integer productId);

    // imgType有1/2/3/4
    ProductImg findImagesByProductId(Integer productId, Integer imgType);

    // orderCartId给NULL，数据库自增
    int insertOrderCart(OrderCart entity);

    int findProductPriceByProductId(Integer productId);

    int insertOrderPay(OrderTable entity);

    int updateProductStockByProductId(Integer productCounts, Integer productId);

    List<Product> findProductTypeId(Integer logType,Integer typeId);

    @Insert("INSERT INTO order_cart (product_id, product_counts, user_id, flag) VALUES (#{productId}, #{productCounts}, #{userId}, 0)")
    int doSaveOrderCart(Integer productId, Integer productCounts, Integer userId);

    @Select("SELECT MAX(order_cart_id) AS orderCartId FROM order_cart WHERE product_id=#{productId} AND product_counts=#{productCounts} AND user_id=#{userId}")
    OrderCart doSaveOrderCartDirectly(Integer productId, Integer productCounts, Integer userId);

    @Insert("INSERT INTO order_table (order_id, product_id, order_cart_id, total_price, site_id) VALUES (#{orderId}, #{productId}, #{orderCartId}, 9999, 1)")
    int insertOrderId(Integer orderId, String productId, Long orderCartId);
}
